package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.organization.entity.db.MbOrgUserIdcard;
import com.corpgovernment.organization.mapper.MbOrgUserIdcardMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author jhxue
 * @create 2022-03-01-14:30
 */
@Component
public class MbOrgUserIdcardLoader {

	@Autowired
	private MbOrgUserIdcardMapper orgUserIdcardMapper;

	public List<MbOrgUserIdcard> selectByUids(List<String> uids) {
		if (CollectionUtils.isEmpty(uids)) {
			return new ArrayList<>();
		}
		Example example = new Example(MbOrgUserIdcard.class);
		example.createCriteria()
			   .andIn("employeeUid", uids)
			   .andEqualTo("deleteTime", new Date(0));
		return orgUserIdcardMapper.selectByExample(example);
	}

    public List<MbOrgUserIdcard> selectByCardType(Integer cardType) {
        if (Objects.isNull(cardType)) {
            return new ArrayList<>();
        }
        Example example = new Example(MbOrgUserIdcard.class);
        example.createCriteria()
                .andEqualTo("cardType", cardType)
                .andEqualTo("deleteTime", new Date(0));
        return orgUserIdcardMapper.selectByExample(example);
    }

}
